import { MICRO_SERVICE_ADMIN, MICRO_SERVICE_GATEWAY } from '~/constants/service-constant.ts'
import type { ApiReq, ApiResp } from '~/api/setting/model/api.ts'

enum Api {
  QueryApiListByMenuId = '/webservice/api/queryApiListByMenuId',
  QueryApiListByNoMenuId = '/webservice/api/queryApiListByNoMenuId',
  QueryApiCheckedListByMenuIdOfPermissionId = '/webservice/api/queryApiCheckedListByMenuIdOfPermissionId',
  CreateApi = '/webservice/api/createApi',
  ModifyApi = '/webservice/api/modifyApi',
  EnabledApiStateById = '/webservice/api/enabledApiStateById',
  RemoveApiById = '/webservice/api/removeApiById',
  BindApiRelationMenu = '/webservice/api/bindApiRelationMenu',
  InitApis = '/webservice/all-micro-service/initApis',
}

/**
 * 根据菜单ID，获取接口列表
 * @param params 接口实体
 */
export function queryApiListByMenuIdApi(params?: ApiReq) {
  return usePost<ApiResp[], ApiReq>(MICRO_SERVICE_ADMIN + Api.QueryApiListByMenuId, params)
}

/**
 * 根据菜单ID为Null，获取接口列表
 * @param params 接口实体
 */
export function queryApiListByNoMenuIdApi(params?: ApiReq) {
  return usePost<ApiResp[], ApiReq>(MICRO_SERVICE_ADMIN + Api.QueryApiListByNoMenuId, params)
}

/**
 * 根据菜单ID，获取根据权限ID标记接口选中列表
 * @param params 接口实体
 */
export function queryApiCheckedListByMenuIdOfPermissionIdApi(params?: ApiReq) {
  return usePost<ApiResp[], ApiReq>(MICRO_SERVICE_ADMIN + Api.QueryApiCheckedListByMenuIdOfPermissionId, params)
}

/**
 * 创建接口
 * @param params 接口实体
 */
export function createApiApi(params?: ApiReq) {
  return usePost<boolean, ApiReq>(MICRO_SERVICE_ADMIN + Api.CreateApi, params)
}

/**
 * 修改接口
 * @param params 接口实体
 */
export function modifyApiApi(params?: ApiReq) {
  return usePost<boolean, ApiReq>(MICRO_SERVICE_ADMIN + Api.ModifyApi, params)
}

/**
 * 开启或关闭接口状态
 * @param params 接口实体
 */
export function enabledApiStateByIdApi(params?: ApiReq) {
  return useGet<boolean, ApiReq>(MICRO_SERVICE_ADMIN + Api.EnabledApiStateById, params)
}

/**
 * 删除接口
 * @param params 接口实体，使用其中ID
 */
export function removeApiByIdApi(params?: ApiReq) {
  return useGet<boolean>(MICRO_SERVICE_ADMIN + Api.RemoveApiById, params)
}

/**
 * 绑定接口和菜单关系
 * @param params 接口实体
 */
export function bindApiRelationMenu(params?: ApiReq) {
  return usePost<boolean, ApiReq>(MICRO_SERVICE_ADMIN + Api.BindApiRelationMenu, params)
}

/**
 * 一键入库接口
 */
export function initApis() {
  return useGet<boolean>(MICRO_SERVICE_GATEWAY + Api.InitApis)
}
